package com.lujieni.springbootjvm.controller;

import com.lujieni.springbootjvm.po.Student;
import com.lujieni.springbootjvm.service.HandlerService;
import com.lujieni.springbootjvm.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class HelloController {

    @Autowired
    private HandlerService handlerService;
    @Autowired
    private HelloService helloService;

    /**
     * 测试线程池中的线程全部timed_waiting的情况
     * jstack pid > show.log 中可以查看
     * arthas中可以使用 thread 命令查看
     * @return
     */
    @GetMapping(value = "/hello")
    public String hello(){
        try {
            TimeUnit.DAYS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "hello";
    }

    @GetMapping(value = "/bye")
    public Student bye(String name){
        Student student = helloService.generateStudent(name);
        return null;
    }

    @GetMapping(value = "/oom")
    public String oom() throws InterruptedException {
        handlerService.handle();
        return "ok";
    }

    @GetMapping(value = "/busy")
    public void busy() throws InterruptedException {
        handlerService.busy();
    }

    @GetMapping(value = "/emailCheck")
    public boolean emailCheck() throws InterruptedException {
        return handlerService.emailCheck();
    }

}
